/**************************************************************************
 * @file usr_uart.c
 * @author 黑马小乌龟 (532352406@qq.com)
 * @brief
 * @version 0.1
 * @date 2025-10-09
 *
 * @copyright Copyright (c) 2025
 *
 *************************************************************************/
#include "usr_cfg.h"
#include "string.h"
#include "usr_uart.h"

/*******************************************************************************
 * Global variable definitions (declared in header file with 'extern')
 ******************************************************************************/

/*******************************************************************************
 * Local function prototypes ('static')
 ******************************************************************************/

/*******************************************************************************
 * Local variable definitions ('static')
 ******************************************************************************/
static en_flag_status_t m_enRxFrameEnd;
static uint16_t m_u16RxLen;
static uint8_t tx_busy=0;
static uint16_t rx_cnt,rx_read_index;
static uint8_t m_au8RxBuf[APP_FRAME_LEN_MAX];
static uint8_t cmd_rx_buf[APP_CMD_FRAME_LEN_MAX];
static uint8_t cmd_tx_buf[APP_CMD_FRAME_LEN_MAX];
static uint8_t g_cmd_buf[APP_CMD_FRAME_LEN_MAX];
static uint8_t cmd[APP_CMD_FRAME_LEN_MAX],param[APP_CMD_FRAME_LEN_MAX];
#define UART_SEND_POOL_MAX_MSG 32
static uint8_t uart_send_pool[UART_SEND_POOL_MAX_MSG][APP_CMD_FRAME_LEN_MAX+1];
static uint8_t pool_put_id=0,pool_get_id=0,pool_active_len=0;
/*******************************************************************************
 * Function implementation - global ('extern') and local ('static')
 ******************************************************************************/
int usr_uart_send_a_msg(char *cmd_str,char *param_str);
void usr_uart_msg_process(void);

uint8_t usr_uart_get_actiove_msg_num_in_pool(void){
    return pool_active_len;
}

RAM_FUNC static int usr_uart_put_msg_to_pool(char *p_buf, uint8_t len) {
    char *p_pool;

    if (p_buf == NULL || len > APP_CMD_FRAME_LEN_MAX) return -1;

    uart_send_pool[pool_put_id][0] = len;
    p_pool = (char *)&uart_send_pool[pool_put_id][1];

    for (int i = 0; i < len; i++) {
        p_pool[i] = p_buf[i];
    }

    pool_put_id++;
    pool_put_id %= UART_SEND_POOL_MAX_MSG;
    pool_active_len++;
    if(pool_active_len>UART_SEND_POOL_MAX_MSG)pool_active_len=UART_SEND_POOL_MAX_MSG;

    return 0;
}

RAM_FUNC static uint8_t *usr_uart_get_msg_from_pool(uint16_t *p_len) {
    uint8_t *msg = NULL;

    if (pool_active_len) {
        pool_active_len--;
        *p_len = uart_send_pool[pool_get_id][0];
        msg = &uart_send_pool[pool_get_id][1];
        pool_get_id++;
        pool_get_id %= UART_SEND_POOL_MAX_MSG;
    }

    return msg;
}

RAM_FUNC void usr_uart_msg_pool_handle(void){
    if(pool_active_len && !tx_busy){
        uint8_t *p_msg;
        uint16_t len;

        p_msg = usr_uart_get_msg_from_pool(&len);
        if(p_msg != NULL){
            usr_uart_send((char *)p_msg,len);
        }
    }
}

/**
 * @brief  DMA transfer complete IRQ callback function.
 * @param  None
 * @retval None
 */
static void RX_DMA_TC_IrqCallback(void) {
    m_enRxFrameEnd = SET;
    m_u16RxLen = APP_FRAME_LEN_MAX;

    USART_FuncCmd(USART_UNIT, USART_RX_TIMEOUT, DISABLE);

    DMA_ClearTransCompleteStatus(RX_DMA_UNIT, RX_DMA_TC_FLAG);
}

/**
 * @brief  DMA transfer complete IRQ callback function.
 * @param  None
 * @retval None
 */
static void TX_DMA_TC_IrqCallback(void) {
    USART_FuncCmd(USART_UNIT, USART_INT_TX_CPLT, ENABLE);
    DMA_ClearTransCompleteStatus(TX_DMA_UNIT, TX_DMA_TC_FLAG);
}

/**
 * @brief  Initialize DMA.
 * @param  None
 * @retval int32_t:
 *           - LL_OK:                   Initialize successfully.
 *           - LL_ERR_INVD_PARAM:       Initialization parameters is invalid.
 */
static int32_t DMA_Config(void) {
    int32_t i32Ret;
    stc_dma_init_t stcDmaInit;
    stc_dma_llp_init_t stcDmaLlpInit;
    stc_irq_signin_config_t stcIrqSignConfig;
    static stc_dma_llp_descriptor_t stcLlpDesc;

    /* DMA&AOS FCG enable */
    RX_DMA_FCG_ENABLE();
    TX_DMA_FCG_ENABLE();
    FCG_Fcg0PeriphClockCmd(FCG0_PERIPH_AOS, ENABLE);

    /* USART_RX_DMA */
    (void)DMA_StructInit(&stcDmaInit);
    stcDmaInit.u32IntEn = DMA_INT_ENABLE;
    stcDmaInit.u32BlockSize = 1UL;
    stcDmaInit.u32TransCount = ARRAY_SZ(m_au8RxBuf);
    stcDmaInit.u32DataWidth = DMA_DATAWIDTH_8BIT;
    stcDmaInit.u32DestAddr = (uint32_t)m_au8RxBuf;
    stcDmaInit.u32SrcAddr = (uint32_t)(&USART_UNIT->RDR);
    stcDmaInit.u32SrcAddrInc = DMA_SRC_ADDR_FIX;
    stcDmaInit.u32DestAddrInc = DMA_DEST_ADDR_INC;
    i32Ret = DMA_Init(RX_DMA_UNIT, RX_DMA_CH, &stcDmaInit);
    if (LL_OK == i32Ret) {
        (void)DMA_LlpStructInit(&stcDmaLlpInit);
        stcDmaLlpInit.u32State = DMA_LLP_ENABLE;
        stcDmaLlpInit.u32Mode = DMA_LLP_WAIT;
        stcDmaLlpInit.u32Addr = (uint32_t)&stcLlpDesc;
        (void)DMA_LlpInit(RX_DMA_UNIT, RX_DMA_CH, &stcDmaLlpInit);

        stcLlpDesc.SARx = stcDmaInit.u32SrcAddr;
        stcLlpDesc.DARx = stcDmaInit.u32DestAddr;
        stcLlpDesc.DTCTLx = (stcDmaInit.u32TransCount << DMA_DTCTL_CNT_POS) | (stcDmaInit.u32BlockSize << DMA_DTCTL_BLKSIZE_POS);
        ;
        stcLlpDesc.LLPx = (uint32_t)&stcLlpDesc;
        stcLlpDesc.CHCTLx = stcDmaInit.u32SrcAddrInc | stcDmaInit.u32DestAddrInc | stcDmaInit.u32DataWidth | stcDmaInit.u32IntEn | stcDmaLlpInit.u32State | stcDmaLlpInit.u32Mode;

        DMA_ReconfigLlpCmd(RX_DMA_UNIT, RX_DMA_CH, ENABLE);
        DMA_ReconfigCmd(RX_DMA_UNIT, ENABLE);
        AOS_SetTriggerEventSrc(RX_DMA_RECONF_TRIG_SEL, RX_DMA_RECONF_TRIG_EVT_SRC);

        stcIrqSignConfig.enIntSrc = RX_DMA_TC_INT_SRC;
        stcIrqSignConfig.enIRQn = RX_DMA_TC_IRQn;
        stcIrqSignConfig.pfnCallback = &RX_DMA_TC_IrqCallback;
        (void)INTC_IrqSignIn(&stcIrqSignConfig);
        NVIC_ClearPendingIRQ(stcIrqSignConfig.enIRQn);
        NVIC_SetPriority(stcIrqSignConfig.enIRQn, DDL_IRQ_PRIO_DEFAULT);
        NVIC_EnableIRQ(stcIrqSignConfig.enIRQn);

        AOS_SetTriggerEventSrc(RX_DMA_TRIG_SEL, RX_DMA_TRIG_EVT_SRC);

        DMA_Cmd(RX_DMA_UNIT, ENABLE);
        DMA_TransCompleteIntCmd(RX_DMA_UNIT, RX_DMA_TC_INT, ENABLE);
        (void)DMA_ChCmd(RX_DMA_UNIT, RX_DMA_CH, ENABLE);
    }

    /* USART_TX_DMA */
    (void)DMA_StructInit(&stcDmaInit);
    stcDmaInit.u32IntEn = DMA_INT_ENABLE;
    stcDmaInit.u32BlockSize = 1UL;
    stcDmaInit.u32TransCount = ARRAY_SZ(m_au8RxBuf);
    stcDmaInit.u32DataWidth = DMA_DATAWIDTH_8BIT;
    stcDmaInit.u32DestAddr = (uint32_t)(&USART_UNIT->TDR);
    stcDmaInit.u32SrcAddr = (uint32_t)m_au8RxBuf;
    stcDmaInit.u32SrcAddrInc = DMA_SRC_ADDR_INC;
    stcDmaInit.u32DestAddrInc = DMA_DEST_ADDR_FIX;
    i32Ret = DMA_Init(TX_DMA_UNIT, TX_DMA_CH, &stcDmaInit);
    if (LL_OK == i32Ret) {
        stcIrqSignConfig.enIntSrc = TX_DMA_TC_INT_SRC;
        stcIrqSignConfig.enIRQn = TX_DMA_TC_IRQn;
        stcIrqSignConfig.pfnCallback = &TX_DMA_TC_IrqCallback;
        (void)INTC_IrqSignIn(&stcIrqSignConfig);
        NVIC_ClearPendingIRQ(stcIrqSignConfig.enIRQn);
        NVIC_SetPriority(stcIrqSignConfig.enIRQn, DDL_IRQ_PRIO_DEFAULT);
        NVIC_EnableIRQ(stcIrqSignConfig.enIRQn);

        AOS_SetTriggerEventSrc(TX_DMA_TRIG_SEL, TX_DMA_TRIG_EVT_SRC);

        DMA_Cmd(TX_DMA_UNIT, ENABLE);
        DMA_TransCompleteIntCmd(TX_DMA_UNIT, TX_DMA_TC_INT, ENABLE);
    }

    return i32Ret;
}

/**
 * @brief  Configure TMR0.
 * @param  [in] u16TimeoutBits:         Timeout bits
 * @retval None
 */
static void TMR0_Config(uint16_t u16TimeoutBits) {
    uint16_t u16Div;
    uint16_t u16Delay;
    uint16_t u16CompareValue;
    stc_tmr0_init_t stcTmr0Init;

    TMR0_FCG_ENABLE();

    /* Initialize TMR0 base function. */
    stcTmr0Init.u32ClockSrc = TMR0_CLK_SRC_LRC;
    stcTmr0Init.u32ClockDiv = TMR0_CLK_DIV8;
    stcTmr0Init.u32Func = TMR0_FUNC_CMP;
    if (TMR0_CLK_DIV1 == stcTmr0Init.u32ClockDiv) {
        u16Delay = 7U;
    } else if (TMR0_CLK_DIV2 == stcTmr0Init.u32ClockDiv) {
        u16Delay = 5U;
    } else if ((TMR0_CLK_DIV4 == stcTmr0Init.u32ClockDiv) || (TMR0_CLK_DIV8 == stcTmr0Init.u32ClockDiv) || (TMR0_CLK_DIV16 == stcTmr0Init.u32ClockDiv)) {
        u16Delay = 3U;
    } else {
        u16Delay = 2U;
    }

    u16Div = (uint16_t)1U << (stcTmr0Init.u32ClockDiv >> TMR0_BCONR_CKDIVA_POS);
    u16CompareValue = ((u16TimeoutBits + u16Div - 1U) / u16Div) - u16Delay;
    stcTmr0Init.u16CompareValue = u16CompareValue;
    (void)TMR0_Init(TMR0_UNIT, TMR0_CH, &stcTmr0Init);

    TMR0_HWStartCondCmd(TMR0_UNIT, TMR0_CH, ENABLE);
    TMR0_HWClearCondCmd(TMR0_UNIT, TMR0_CH, ENABLE);
}

/**
 * @brief  USART RX timeout IRQ callback.
 * @param  None
 * @retval None
 */
static void USART_RxTimeout_IrqCallback(void) {
    if (m_enRxFrameEnd != SET) {
        m_enRxFrameEnd = SET;
        m_u16RxLen = APP_FRAME_LEN_MAX - (uint16_t)DMA_GetTransCount(RX_DMA_UNIT, RX_DMA_CH);

        /* Trigger for re-config USART RX DMA */
        AOS_SW_Trigger();
    }

    TMR0_Stop(TMR0_UNIT, TMR0_CH);

    USART_ClearStatus(USART_UNIT, USART_FLAG_RX_TIMEOUT);
}

/**
 * @brief  USART TX complete IRQ callback function.
 * @param  None
 * @retval None
 */
static void USART_TxComplete_IrqCallback(void) { 
    USART_FuncCmd(USART_UNIT, (USART_TX | USART_INT_TX_CPLT), DISABLE); 
    // DDL_Printf("UART1.\n");
    tx_busy = 0;
}

/**
 * @brief  USART RX error IRQ callback.
 * @param  None
 * @retval None
 */
static void USART_RxError_IrqCallback(void) {
    (void)USART_ReadData(USART_UNIT);

    USART_ClearStatus(USART_UNIT, (USART_FLAG_PARITY_ERR | USART_FLAG_FRAME_ERR | USART_FLAG_OVERRUN));
}

/**
 * @brief  Main function of UART DMA project
 * @param  None
 * @retval int32_t return value, if needed
 */
int32_t usr_uart_init(void) {
    stc_usart_uart_init_t stcUartInit;
    stc_irq_signin_config_t stcIrqSigninConfig;

    /* MCU Peripheral registers write unprotected */
    // LL_PERIPH_WE(LL_PERIPH_SEL_USR_UART);

    /* Initialize DMA. */
    (void)DMA_Config();

    /* Initialize TMR0. */
    TMR0_Config(USART_TIMEOUT_BITS);

    /* Configure USART RX/TX pin. */
    GPIO_SetFunc(USART_RX_PORT, USART_RX_PIN, USART_RX_GPIO_FUNC);
    GPIO_SetFunc(USART_TX_PORT, USART_TX_PIN, USART_TX_GPIO_FUNC);

    /* Enable peripheral clock */
    USART_FCG_ENABLE();

    /* Initialize UART. */
    (void)USART_UART_StructInit(&stcUartInit);
    stcUartInit.u32ClockDiv = USART_CLK_DIV4;
    stcUartInit.u32CKOutput = USART_CK_OUTPUT_ENABLE;
    stcUartInit.u32Baudrate = USART_BAUDRATE;
    stcUartInit.u32OverSampleBit = USART_OVER_SAMPLE_8BIT;
    if (LL_OK != USART_UART_Init(USART_UNIT, &stcUartInit, NULL)) {
        // BSP_LED_On(LED_RED);
        DDL_Printf("UART init failed\n");
        return -1;
    }

    /* Register TX complete IRQ handler. */
    stcIrqSigninConfig.enIRQn = USART_TX_CPLT_IRQn;
    stcIrqSigninConfig.enIntSrc = USART_TX_CPLT_INT_SRC;
    stcIrqSigninConfig.pfnCallback = &USART_TxComplete_IrqCallback;
    (void)INTC_IrqSignIn(&stcIrqSigninConfig);
    NVIC_ClearPendingIRQ(stcIrqSigninConfig.enIRQn);
    NVIC_SetPriority(stcIrqSigninConfig.enIRQn, DDL_IRQ_PRIO_DEFAULT);
    NVIC_EnableIRQ(stcIrqSigninConfig.enIRQn);

    /* Register RX error IRQ handler. */
    stcIrqSigninConfig.enIRQn = USART_RX_ERR_IRQn;
    stcIrqSigninConfig.enIntSrc = USART_RX_ERR_INT_SRC;
    stcIrqSigninConfig.pfnCallback = &USART_RxError_IrqCallback;
    (void)INTC_IrqSignIn(&stcIrqSigninConfig);
    NVIC_ClearPendingIRQ(stcIrqSigninConfig.enIRQn);
    NVIC_SetPriority(stcIrqSigninConfig.enIRQn, DDL_IRQ_PRIO_DEFAULT);
    NVIC_EnableIRQ(stcIrqSigninConfig.enIRQn);

    /* Register RX timeout IRQ handler. */
    stcIrqSigninConfig.enIRQn = USART_RX_TIMEOUT_IRQn;
    stcIrqSigninConfig.enIntSrc = USART_RX_TIMEOUT_INT_SRC;
    stcIrqSigninConfig.pfnCallback = &USART_RxTimeout_IrqCallback;
    (void)INTC_IrqSignIn(&stcIrqSigninConfig);
    NVIC_ClearPendingIRQ(stcIrqSigninConfig.enIRQn);
    NVIC_SetPriority(stcIrqSigninConfig.enIRQn, DDL_IRQ_PRIO_DEFAULT);
    NVIC_EnableIRQ(stcIrqSigninConfig.enIRQn);

    /* MCU Peripheral registers write protected */
    // LL_PERIPH_WP(LL_PERIPH_SEL_USR_UART);

    /* Enable TX && RX && RX interrupt function */
    USART_FuncCmd(USART_UNIT, (USART_RX | USART_INT_RX | USART_RX_TIMEOUT | USART_INT_RX_TIMEOUT), ENABLE);
    rx_cnt = 0;
    rx_read_index = 0;

    // for (;;) {
    //     if (SET == m_enRxFrameEnd) {
    //         DMA_SetSrcAddr(TX_DMA_UNIT, TX_DMA_CH, (uint32_t)m_au8RxBuf);
    //         DMA_SetTransCount(TX_DMA_UNIT, TX_DMA_CH, m_u16RxLen);
    //         (void)DMA_ChCmd(TX_DMA_UNIT, TX_DMA_CH, ENABLE);
    //         USART_FuncCmd(USART_UNIT, USART_TX, ENABLE);
    //         m_enRxFrameEnd = RESET;
    //     }
    // }
    return 0;
}

RAM_FUNC int usr_uart_send(char *p_buf, uint16_t len) {
    int ret=-1;
    
    if(p_buf != NULL){
        if(!tx_busy){
            memcpy(cmd_tx_buf,p_buf,len);
            DMA_SetSrcAddr(TX_DMA_UNIT, TX_DMA_CH, (uint32_t)cmd_tx_buf);
            DMA_SetTransCount(TX_DMA_UNIT, TX_DMA_CH, len);
            (void)DMA_ChCmd(TX_DMA_UNIT, TX_DMA_CH, ENABLE);
            USART_FuncCmd(USART_UNIT, USART_TX, ENABLE);
            ret = 0;
            tx_busy = 1;
        }else{
            usr_uart_put_msg_to_pool(p_buf,len);
        }
        
    }
    
    return ret;
}

RAM_FUNC int usr_uart_send_a_msg(char *cmd_str,char *param_str){
    int ret;
    char msg_pkg[APP_CMD_FRAME_LEN_MAX]={0};
    sprintf(msg_pkg,"<%s=%s>",cmd_str,param_str);
    // DDL_Printf("SEND MSG: [%s]", msg_pkg);
    ret = usr_uart_send(msg_pkg,strlen(msg_pkg));
    if(ret == -1){
        // DDL_Printf("error: UART IS BUSY!!!\n");
    }

    return ret;
}

RAM_FUNC uint8_t *usr_uart_get_msg_pkg_handle(void) {
    uint16_t i;

    if (SET == m_enRxFrameEnd) {
        for (i = 0; i < m_u16RxLen; i++) {
            cmd_rx_buf[rx_cnt++] = m_au8RxBuf[i];
            rx_cnt %= APP_CMD_FRAME_LEN_MAX;
        }
        m_enRxFrameEnd = RESET;
    }

    /*find a cmd pkg*/
    if (rx_read_index != rx_cnt) {
        uint8_t head_flg = 0;
        uint16_t tmp_read = rx_read_index;
        i = 0;
        uint8_t t_dat;
        while (tmp_read != rx_cnt) {
            t_dat = cmd_rx_buf[tmp_read++];
            tmp_read %= APP_CMD_FRAME_LEN_MAX;
            if (t_dat == '<') {
                i = 0;
                head_flg = 1;
                g_cmd_buf[i++] = t_dat;
            } else {
                if (head_flg) {
                    g_cmd_buf[i++] = t_dat;
                    if (t_dat == '>') {
                        g_cmd_buf[i++] = '\0';
                        rx_read_index = tmp_read;
                        return g_cmd_buf;
                    }
                }
            }
        }
    }
    return NULL;
}


RAM_FUNC static char *usr_get_uart_msg_cmd_str(char *p_msg_pkg, uint16_t pkg_len)
{
    char *buf;
    uint8_t i, cmd_len = 0, head_flg = 0;
    uint16_t str_len;

    if (p_msg_pkg == NULL)
        return NULL;
    str_len = pkg_len;
    if (str_len > APP_CMD_FRAME_LEN_MAX)
        return NULL;

    buf = (char*)cmd;
    for (i = 0; i < str_len; i++) {
        if (p_msg_pkg[i] == '<') {
            head_flg = 1;
            cmd_len  = 0;
        } else {
            if (p_msg_pkg[i] == '=') {
                break;
            }
            if (head_flg) {
                buf[cmd_len++] = p_msg_pkg[i];
            }
        }
    }

    if (cmd_len) {
        buf[cmd_len] = '\0';
        return buf;
    } else {
        // free(buf);
        return NULL;
    }
}

static char *usr_get_uart_msg_cmd_param_str(char *p_msg_pkg, uint16_t pkg_len)
{
    char *buf;
    uint8_t i, param_len = 0, head_flg = 0;
    uint16_t str_len;

    if (p_msg_pkg == NULL)
        return NULL;
    str_len = pkg_len;
    if (str_len > APP_CMD_FRAME_LEN_MAX)
        return NULL;

    buf = (char *)param;
    for (i = 0; i < str_len; i++) {
        if (p_msg_pkg[i] == '<') {
            head_flg = 1;
        }

        if (head_flg) {
            if (p_msg_pkg[i] == '=') {
                param_len = 0;
            } else {
                if (p_msg_pkg[i] == '>') {
                    break;
                }
                buf[param_len++] = p_msg_pkg[i];
            }
        }
    }

    if (param_len) {
        buf[param_len] = '\0';
        return buf;
    } else {
        // free(buf);
        return NULL;
    }
}

extern void usr_sync_cfg_to_host_handle(void);
static void usr_uart_msg_handle(char *cmd, char *param)
{
    if (strcmp(OUTPUT_VOLTAGE_CMD, cmd) == 0) {
        
    } else if (strcmp(INPUT_VOLTAGE_CMD, cmd) == 0) {
        
    } else if (strcmp(OUTPUT_CURRENT_CMD, cmd) == 0) {
        
    } else if (strcmp(OUTPUT_STATE_CMD, cmd) == 0) {
        if (strcmp("OFF", param) == 0) {
            
        } else {
        
            if(strcmp("CV", param) == 0){
                
            }else{
                
            }
        }

    } else if (strcmp(INPUT_STATE_CMD, cmd) == 0) {
        
    } else if (strcmp(SET_OUT_VOLTAGE, cmd) == 0) {
        
    } else if (strcmp(SET_OUT_CURRENT, cmd) == 0) {
        
    } else if (strcmp(SET_ACTIVE_INFOR, cmd) == 0) {
        // va: 表示设置电压有效
        // ia: 表示设置电流有效
        // off: 表示设置电压电流无效
        if (strcmp("va", param) == 0) {
        }
        if (strcmp("ia", param) == 0) {
        } else {
        }
    } else if (strcmp(BUCK_BOOST_MCU_VER, cmd) == 0) {
    } else if (strcmp(PD_MCU_VERSION, cmd) == 0) {    
    } else if (strcmp(HOST_SYNC_DAT_CMD, cmd) == 0) {   
        usr_sync_cfg_to_host_handle();
    } else {
        DDL_Printf("cmd:%s is not support!\n", cmd);
    }
}

void usr_uart_msg_process(void){
    char *pkg,*cmd_buf,*param_buf;
    uint16_t len;

    pkg = (char*)usr_uart_get_msg_pkg_handle();
    if(pkg!=NULL){
        len = strlen(pkg);
        // usr_uart_send(pkg,len);
        cmd_buf = usr_get_uart_msg_cmd_str(pkg, len);
        if (cmd_buf == NULL) {
            return;
        }
        DDL_Printf("cmd:%s\n", cmd_buf);
        param_buf = usr_get_uart_msg_cmd_param_str(pkg, len);
        if (param_buf != NULL) {
            DDL_Printf("param:%s\n", param_buf);
            usr_uart_msg_handle(cmd_buf, param_buf);
            
        } else {
            DDL_Printf("cmd:%s is no parameters\n", cmd_buf);
        }
    }
    
}